﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="ShoppingTemplate.GroupedItemsPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    IsTabStop="false"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ShoppingTemplate"
    xmlns:data="using:ShoppingTemplate.Data"
    xmlns:common="using:ShoppingTemplate.Common"
    xmlns:tileStyle="using:ShoppingTemplate.VariableTemplate"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>
        <!-- Collection of grouped items displayed by this page -->
        <CollectionViewSource
            x:Name="groupedItemsViewSource"
            Source="{Binding Groups}"
            IsSourceGrouped="true"
            ItemsPath="Items"
            d:Source="{Binding ItemGroups, Source={d:DesignInstance Type=data:SampleDataSource, IsDesignTimeCreatable=True}}"/>

        <tileStyle:VariableTiles x:Key="MyTemplateSelectorObj"
                    BigTemplate="{StaticResource BigItemTemplate}"
                    MediumTemplate="{StaticResource MediumItemTemplate}"
                    SmallTemplate="{StaticResource SmallItemTemplate}"/>


    </Page.Resources>
    <Page.TopAppBar>
        <AppBar x:Name="topappBar" Padding="5,0,0,0">
            <Grid>
                <StackPanel Orientation="Horizontal">
                    <!--<Button x:Name="btnHome" HorizontalAlignment="Left" Style="{StaticResource HomeAppBarButtonStyle}" IsEnabled="False"/>-->
                    <Button x:Name="btnHome" HorizontalAlignment="Left" Padding="0" Background="Transparent" Margin="15,0,20,0" Click="btnHome_Click">
                        <Button.Content>
                            <Image Source="/Assets/Images/Home.png" Height="60" Width="60"/>
                        </Button.Content>
                    </Button>
                    <Button HorizontalAlignment="Left" Padding="0" Background="Transparent" Margin="0,0,20,0">
                        <Button.Content>
                            <Image Source="/Assets/Images/section1.png" Height="60" Width="60"/>
                        </Button.Content>
                    </Button>
                    <Button HorizontalAlignment="Left" Padding="0" Background="Transparent" Margin="0,0,20,0">
                        <Button.Content>
                            <Image Source="/Assets/Images/section2.png" Height="60" Width="60"/>
                        </Button.Content>
                    </Button>
                    <Button HorizontalAlignment="Left" Padding="0" Background="Transparent" Margin="0,0,20,0">
                        <Button.Content>
                            <Image Source="/Assets/Images/section3.png" Height="60" Width="60"/>
                        </Button.Content>
                    </Button>
                </StackPanel>

                <StackPanel HorizontalAlignment="Right">
                    <Button HorizontalAlignment="Left" Padding="0" Background="Transparent" Margin="0,0,20,0">
                        <Button.Content>
                            <Image Source="/Assets/Images/ShoppingCart.png" Height="80" Width="100"/>
                        </Button.Content>
                    </Button>
                </StackPanel>
            </Grid>
        </AppBar>
    </Page.TopAppBar>
    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid>
        <Grid.Background>
            <ImageBrush ImageSource="Assets/Images/Bg1.png"/>
        </Grid.Background>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Grid.Column="1" Style="{StaticResource PageHeaderTextStyle}" Foreground="#FF999364" Text="Page Header"/>
            <Image x:Name="imgLogo" Margin="0,0,10,0" Grid.Column="1" HorizontalAlignment="Right" Width="234" Height="100" VerticalAlignment="Center" 
                   Source="/Assets/AppLogo.png"/>
        </Grid>

        <!-- Horizontal scrolling grid used in most view states -->
        <tileStyle:VariableTileControl
                x:Name="itemGridView"
                AutomationProperties.AutomationId="ItemGridView"
                AutomationProperties.Name="Grouped Items"
                Padding="116,0,40,46"
                ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
                ItemTemplateSelector="{StaticResource MyTemplateSelectorObj}"
                Grid.Row="1"
                SelectionMode="None"
                IsItemClickEnabled="True"
                ItemClick="ItemView_ItemClick">

            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
            <GridView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Margin="1,0,0,6">
                                <Button
                                        AutomationProperties.Name="Group Title"
                                        Content="{Binding Title}"
                                        Click="Header_Click"
                                        Style="{StaticResource TextButtonStyle}"/>
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <VariableSizedWrapGrid ItemHeight="80" ItemWidth="125" MaximumRowsOrColumns="6" Orientation="Vertical" Margin="0,0,20,0"/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </GridView.GroupStyle>
        </tileStyle:VariableTileControl>

        <!-- Vertical scrolling list only used when snapped -->
        <ListView
                x:Name="itemListView"
                AutomationProperties.AutomationId="ItemListView"
                AutomationProperties.Name="Grouped Items"
                Padding="10,-10,0,60"
                ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
                ItemTemplate="{StaticResource Standard80ItemTemplate}"
                SelectionMode="None"
                IsItemClickEnabled="True"
                Grid.Row="1"
                Visibility="Collapsed"
                ItemClick="ItemView_ItemClick">

            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Margin="7,7,0,0">
                                <Button
                                        AutomationProperties.Name="Group Title"
                                        Content="{Binding Title}"
                                        Click="Header_Click"
                                        Style="{StaticResource TextButtonStyle}"/>
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </ListView.GroupStyle>
        </ListView>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup>
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="96,0,10,56"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!--
                    The back button and title have different styles when snapped, and the list representation is substituted
                    for the grid displayed in all other view states
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="imgLogo" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
